package com.ymxk.timestar.activity.smriti;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.zxn.xm.text.FadeInTextView;
import com.zxn.xmtextdemo.R;

/**
 * 传承引导页、
 */
public class SmritiGuideActivity extends AppCompatActivity {

    private FadeInTextView tvSmritiDesc;

    public static void jumpTo(Context context) {
        Intent intent = new Intent(context, SmritiGuideActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        initViews();
    }

    protected int getLayoutId() {
        return R.layout.activity_smriti_guide;
    }


    protected void initViews() {
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        findViewById(R.id.tvSmritiNext).setOnClickListener(v -> onJumpNext());
        findViewById(R.id.tvConfirm).setOnClickListener(v -> onShowSmritiDialog());
        findViewById(R.id.ivBubble).setOnClickListener(v -> onShowSelectHeirDialog());
        findViewById(R.id.ivLesserBubble).setOnClickListener(v -> onShowSelectHeirDialog());
        tvSmritiDesc = findViewById(R.id.tvSmritiDesc);
        String context = getString(R.string.text_smriti_desc);
        tvSmritiDesc.setTextString(context)
                .setDuration(100)
                .setTextAnimationListener(this::onSmritiDescEnd)
                .startFadeInAnimation();
    }

    private void onSmritiDescEnd() {
        //Toast.makeText(this, "结束", Toast.LENGTH_SHORT).show();
        String content = getString(R.string.text_smriti_desc);
        tvSmritiDesc.setTextString(content);

        findViewById(R.id.ivSmritiBall).setVisibility(View.VISIBLE);
        FadeInTextView tvInheritIntroduce = findViewById(R.id.tvInheritIntroduce);
        tvInheritIntroduce.setVisibility(View.VISIBLE);
        String context = getString(R.string.text_inherit_introduce);

        tvInheritIntroduce.setTextString(context)
                .setPartTextColor(Color.parseColor("#19FFEB"), 22, 31)
                .setPartTextColor(Color.parseColor("#19FFEB"), 54, context.length() + 1)
                .setDuration(55)
                .setTextAnimationListener(this::onInheritIntroduceEnd)
                .startFadeInAnimation();

    }

    private void onInheritIntroduceEnd() {

    }

    private void onShowSmritiDialog() {
        //SmritiDialogFragment.newInstance().show(getSupportFragmentManager(), "SmritiDialogFragment");
    }

    private void onJumpNext() {
        //Toast.makeText(this, "onJumpNext", Toast.LENGTH_SHORT).show();
        //tvSmritiDesc.stopFadeInAnimation();
    }

    private void onShowSelectHeirDialog() {
        //SmritiHeirDialogFragment.newInstance().show(getSupportFragmentManager(), "SmritiHeirDialogFragment");
    }
}